/*!
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 *    Author: flareguner
 *    E-Mail: flareguner@gmail.com
 *    Years: 2010-2010
 */

#include "about.h"
#include "src/platform.h"
#include "icons.h"
#include <QtGui/QTabWidget>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QFrame>
#include <QtGui/QVBoxLayout>
#include <QtGui/QTextBrowser>
#include <QtCore/QEvent>
#include <QtCore/QFile>


About::About(QWidget *parent) :
    QDialog(parent)
{
    createUi();
    createText();

    connect(dialogButtons/*->button(QDialogButtonBox::Close)*/,
	    SIGNAL(accepted()), this, SLOT(accept()));
}

About::~About()
{
    delete tabWidget;
    delete dialogButtons;
    delete horizontalLine;
    delete mainLayout;
    delete aboutTextBrowser;
    delete developersTextBrowser;
    delete creditsTextBrowser;
    delete licenseTextBrowser;
}

void About::loadNativeIcons() {
    this->setWindowIcon(Icons::nativeIcon("help-browser"));

}

void About::loadDefaultIcons() {
    this->setWindowIcon(Icons::defaultIcon("help-browser"));
}

void About::changeEvent(QEvent *e) {
    if(e->type() == QEvent::LanguageChange) {
	this->setWindowTitle(QDialog::tr("QGoogleTranslator - about"));
	tabWidget->setTabText(0, QTabWidget::tr("About"));
	tabWidget->setTabText(1, QTabWidget::tr("Developers"));
	tabWidget->setTabText(2, QTabWidget::tr("Credits"));
	tabWidget->setTabText(3, QTabWidget::tr("License"));
    }
}

void About::createUi(){
    aboutTextBrowser = new QTextBrowser(this);
    developersTextBrowser = new QTextBrowser(this);
    creditsTextBrowser = new QTextBrowser(this);
    licenseTextBrowser = new QTextBrowser(this);

    tabWidget = new QTabWidget(this);
    tabWidget->addTab(aboutTextBrowser, tr("Common"));
    tabWidget->addTab(developersTextBrowser, tr("Developers"));
    tabWidget->addTab(creditsTextBrowser, tr("Credits"));
    tabWidget->addTab(licenseTextBrowser, tr("License"));

    tabWidget->setLayout(new QVBoxLayout());

    horizontalLine = new QFrame(this);
    horizontalLine->setFrameShape(QFrame::HLine);
    horizontalLine->setFrameShadow(QFrame::Sunken);

    dialogButtons = new QDialogButtonBox(this);
    dialogButtons->setStandardButtons(QDialogButtonBox::Close);

    mainLayout = new QVBoxLayout;

    mainLayout->addWidget(tabWidget);
    mainLayout->addWidget(horizontalLine);
    mainLayout->addWidget(dialogButtons);

    this->setLayout(mainLayout);
}

void About::createText() {
    QString about;
    about.append("QGoogleTranslator v 1.2\n\n");
    about.append("QGoogleTranslator is a tiny and powerful GUI for Google Translate service\n\n");
    about.append("Project home: http://code.google.com/p/qgt\n\n");
    about.append("Copyright(c) QGoogleTranslator developers\n\n");
    about.append("Google(tm) and Google(tm) logo are registered trademarks of Google inc.");
    about.append("All rights reserved.");
    about.append("Big tranks Google inc for good and free translation service!");

    QString developers;
    developers.append("Developers:\n");
    developers.append("flareguner - project author and owner");
    developers.append(" flareguner@gmail.com\n");
    developers.append("arsi - developer. arsi.dev@gmail.com\n");

    developers.append("Translators:\n");
    developers.append("urxvt - Ukrainian translation voice@root.ua\n");

    developers.append("Maintainers:\n");
    developers.append("prodoomman - Ubuntu PPA maintainer");
    developers.append("prodoomman@gmail.com");


    QString credits;
    credits.append("Big thanks /dev/aurasniffer for help with English localisation");

    QFile file(Platform::getLicensePath());
    file.open(QFile::ReadOnly);
    QString license = file.readAll();
    file.close();

    aboutTextBrowser->setPlainText(about);
    developersTextBrowser->setPlainText(developers);
    creditsTextBrowser->setPlainText(credits);
    licenseTextBrowser->setPlainText(license);
}
